﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class showLCMDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] == null || Session["roleID"] == null)
        {
            Response.Redirect("Login.aspx");
            Response.End();
        }
        if (Request.QueryString["flowmid"] == null)
        {
            Response.Redirect("NoAccess.htm");
        }
        if (!Page.IsPostBack)
        {
            if (Request.UrlReferrer != null)
            {
                lblBackUrl.Text = Request.UrlReferrer.ToString();
            }
            else
            {
                lblBackUrl.Text = "FlowModelList.aspx";
            }
            int flowMID = Convert.ToInt32(Request.QueryString["flowmid"].ToString());
            lblFlowMID.Text = flowMID.ToString();
            BindToDdlFlowMType();
            BindToLCMMsg(flowMID);
            if (Session["roleID"].ToString() != "1")
            {
                btnSubmit.Visible = false;
                btnReset.Visible = false;
            }
        }
    }
    private void BindToDdlFlowMType()
    {
        string sqlString = "select * from FLOWTYPE order by FLOWTYPEID ASC";
        DBOperation DBO = new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);
        ddlFlowMType.DataSource = sdr;
        ddlFlowMType.DataTextField = "TYPENAME";
        ddlFlowMType.DataValueField = "FLOWTYPEID";
        ddlFlowMType.DataBind();
        sdr.Close();
    }
    protected void BindToLCMMsg(int flowMID)
    {
        FlowModel tempFM = new FlowModel(flowMID);
        txtFlowMName.Text = tempFM.FlowName.ToString();
        txtFlowMBrief.Text = tempFM.Brief.ToString();
        lblUserName.Text = BasicClass.GetTrueNameByUserName(tempFM.UserName.ToString());
        ddlFlowMType.SelectedValue = tempFM.FlowTypeID.ToString();        
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int flowMID=Convert.ToInt32(lblFlowMID.Text.ToString());
        FlowModel tempFM = new FlowModel(flowMID);
        tempFM.FlowName = txtFlowMName.Text;
        tempFM.FlowTypeID = Convert.ToInt32(ddlFlowMType.SelectedValue);
        tempFM.Brief = txtFlowMBrief.Text;
        tempFM.UpdateFlowModel();
        Response.Redirect("FlowModelList.aspx");
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string refURL = "MessageInfo.aspx";

        refURL = lblBackUrl.Text;
        if (refURL == "" || refURL == null || refURL == "MenuDir.aspx")
        {
            refURL = "MessageInfo.aspx";
        }
        Response.Redirect(refURL);
    }
    protected void btnFlowSteps_Click(object sender, EventArgs e)
    {
        string flowid=lblFlowMID.Text.ToString().Trim();
        Response.Redirect("FlowStepSet.aspx?flowid=" + flowid);
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Response.Redirect("showLCMDetail.aspx?flowmid=" + Request.QueryString["flowmid"].ToString());

    }
}
